#pragma once
#include <libintl.h>
#include <stdio.h>
#include <string.h>
#include "utils.h"

void help_agm() {
	puts(gettext("\
Special mean:\n\
  agm <x> <y>\n\n\
Calculate arithmetic-geometric mean.\n\
  See also `?ghm` (geometric-harmonic mean)."));
}

void help_append() {
	puts(gettext("\
Append elements to the end of lists:\n\
  append <var> <numbers...>\n\n\
There are 26 variable name(\"A\"~\"Z\", ignore case) supported.\n\
Use SPACE to split each element."));
}

void help_chart() {
	puts(gettext("\
Draw chart:\n\
  chart draw\n\
  chart reset\n\
  chart settype <type> [option]\n\
  chart setx <var>\n\
  chart sety <var>\n\n\
Use Tcl/Tk to draw chart.\n\n\
Available values for argument `type` and supported `option`s:\n\
  - bar\n\
    - <no option>\n\
  - line\n\
    - drawdot\n\
  - scatter\n\
    - la=<type=none|slr>"));
}

void help_cmdargs(char *name) {
	printf(gettext("Usage: %s -hqV\n\n"), name);
	puts(gettext("\
Options:\n\
  -h, --help    Show help\n\
  -q            Hide version messages on startup\n\
  -V, --version Show version info"));
}

void help_exit() {
	puts(gettext("\
Quit Counts:\n\
  exit\n\
  quit"));
}

void help_ghm() {
	puts(gettext("\
Special mean:\n\
  ghm <x> <y>\n\n\
Calculate geometric-harmonic mean.\n\
  See also `?agm` (arithmetic-geometric mean)."));
}

void help_load() {
	puts(gettext("\
Load data from a file:\n\
  load <filename>\n\n\
You can use `save <filename>` to save data."));
}

void help_save() {
	puts(gettext("\
Save data to a file:\n\
  save <filename>\n\n\
You can use `load <filename>` to load data."));
}

void help_show() {
	puts(gettext("\
Show elements in list:\n\
  show <var> [condition] [op] [condition]\n\n\
If `condition` exists, just show values eligible.\n\n\
`condition`:\n\
  - >=value\n\
  - <=value\n\
  - >value\n\
  - <value\n\
  - !=value\n\
  - =value\n\n\
`op`:\n\
  - and, &&\n\
  - or , ||"));
}

void help_sort() {
	puts(gettext("\
Sort the list:\n\
  sort <var> <type>\n\n\
Available values of argument `type`:\n\
  - asc\n\
  - desc"));
}

void help_statistic() {
	puts(gettext("\
Statistic:\n\
  statistic <var> <type>\n\n\
Available values of argument `type`:\n\
  - gmean (Geometric mean)\n\
  - hmean (Harmonic mean)\n\
  - max\n\
  - mean\n\
  - min\n\
  - qmean (Quadratic mean)\n\
  - sum"));
}

void print_license() {
	int major, minor, patch;
	get_version(&major, &minor, &patch);
	printf("Counts %d.%d.%d\n", major, minor, patch);
	puts("Copyright (c) 2021 Jason Zheng");
	puts(gettext("license GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>."));
	puts(gettext("This is free software: you are free to change and redistribute it."));
	puts(gettext("There is NO WARRANTY, to the extent permitted by law.\n"));
	puts(gettext("Written by Jason Zheng."));
	puts(gettext("You can find the source code at: <https://github.com/jason-bowen-zheng/counts>."));
}

void print_help(char *topic) {
	if (strcmp(topic, "agm") == 0) {
		help_agm();
	} else if (strcmp(topic, "append") == 0) {
		help_append();
	} else if (strcmp(topic, "chart") == 0) {
		help_chart();
	} else if ((strcmp(topic, "exit") == 0) || (strcmp(topic, "quit") == 0)) {
		help_exit();
	} else if (strcmp(topic, "ghm") == 0) {
		help_ghm();
	} else if (strcmp(topic, "license") == 0) {
		print_license();
	} else if (strcmp(topic, "load") == 0) {
		help_load();
	} else if (strcmp(topic, "save") == 0) {
		help_save();
	} else if (strcmp(topic, "show") == 0) {
		help_show();
	} else if (strcmp(topic, "sort") == 0) {
		help_sort();
	} else if (strcmp(topic, "statistic") == 0) {
		help_statistic();
	} else {
		printf(gettext("No topic \"%s\" found.\n"), topic);
	}
}

